package com.logistic.server.controller;

import com.logistic.server.common.annotation.LoginRequired;
import com.logistic.server.entity.common.PageRequest;
import com.logistic.server.entity.common.Result;
import com.logistic.server.entity.common.ResultGenerator;
import com.logistic.server.entity.pojo.SysPost;
import com.logistic.server.service.ISysPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 岗位信息操作处理
 *
 * @author swen
 */
@Api(value = "岗位信息控制器", tags = {"岗位信息管理"})
@RestController
@LoginRequired
@RequestMapping("/system/post")
public class SysPostController {

    @Resource
    private ISysPostService postService;

    /**
     * 获取岗位列表
     * @param post 岗位信息
     */
    @ApiOperation("获取岗位列表")
    @GetMapping
    public Result<?> list(SysPost post, PageRequest pageRequest) {
        return ResultGenerator.genSuccessResult(postService.selectPagePostList(post, pageRequest));
    }


    /**
     * 根据岗位编号获取详细信息
     * @param postId 岗位id
     */
    @ApiOperation("根据岗位编号获取详细信息")
    @GetMapping(value = "/{postId}")
    public Result<SysPost> getInfo(@PathVariable Long postId) {
        return ResultGenerator.genSuccessResult(postService.selectPostById(postId));
    }

    /**
     * 新增岗位
     * @param post 岗位信息
     * @return 结果
     */
    @ApiOperation("新增岗位")
    @PostMapping
    public Result<?> add(@Validated @RequestBody SysPost post) {
        postService.insertPost(post);
        return ResultGenerator.genSuccessResult();
    }

    /**
     * 修改岗位
     * @param post 岗位信息
     * @return 结果
     */
    @ApiOperation("修改岗位")
    @PutMapping
    public Result<?> edit(@Validated @RequestBody SysPost post) {
        postService.updatePost(post);
        return ResultGenerator.genSuccessResult();
    }

    /**
     * 删除岗位
     * @param postIds ids
     * @return 结果
     */
    @ApiOperation("删除岗位")
    @DeleteMapping("/{postIds}")
    public Result<?> remove(@PathVariable Long[] postIds) {
        postService.deletePostByIds(postIds);
        return ResultGenerator.genSuccessResult();
    }

    /**
     * 获取岗位选择框列表
     * @return 结果
     */
    @ApiOperation("获取岗位选择框列表")
    @GetMapping("/optionSelect")
    public Result<List<SysPost>> optionSelect() {
        return ResultGenerator.genSuccessResult(postService.selectPostAll());
    }
}
